#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
using namespace std;
int times,n,len;
vector<string> DNA;

string chs = "ACGT";

int main(){
    scanf("%d",&times);
    while(times--){
        scanf("%d%d",&n,&len);
        DNA.clear();
        for(int i=0;i<n;i++){
            string tmp="";
            cin>>tmp;
            DNA.push_back(tmp);
        }
        vector<int> count; // 换一个维度统计相同位置上出现的相同字符的频率
        string ans(len,'A');
        for(int i=0;i<len;i++){
            int num[4]={0};
            for(int j=0;j<n;j++){
                 num[chs.find(DNA[j][i])]++;
            }
            int max_index = 0;
            for(int j=1;j<4;j++){
                max_index = num[j]>num[max_index] ? j : max_index;
            }
            count.push_back(num[max_index]);
            ans[i] = chs[max_index];
        }
        cout<<ans<<endl;
        int total_counts = n*len,total_equal=0;
        for(int i=0;i<len;i++)
            total_equal+=count[i];
        cout<<total_counts - total_equal<<endl;
    }

    return 0;
}